package com.big_data.main.resp;

import static com.big_data.main.resp.ErrorCode.SUCCESS_OPTION;

public class RespUtil {

    public static <T> ResponseBean<T> success(T data) {
        ResponseBean<T> resp = new ResponseBean<>();
        resp.setCode(SUCCESS_OPTION.getCode());
        resp.setMessage(SUCCESS_OPTION.getMessage());
        resp.setData(data);
        return resp;
    }

    public static ResponseBean<?> success() {
        return success(null);
    }

    public static <T> ResponseBean<T> fail(ErrorCode ec) {
        ResponseBean<T> resp = new ResponseBean<>();
        resp.setCode(ec.getCode());
        resp.setMessage(ec.getMessage());
        return resp;
    }

    public static ResponseBean<?> fail(String message) {
        ResponseBean<?> resp = new ResponseBean<>();
        resp.setMessage(message);
        return resp;
    }
}
